

%% (de)-stabilizing effect of GDP growth on elite turnover
pr_retainPower_aut=exp(alpha+theta(1)*(-1:0.01:1));
pr_retainPower_aut=mean(pr_retainPower_aut./(1+pr_retainPower_aut),1)';
pr_retainPower_dem=exp(alpha+theta(2)*(-1:0.01:1)-f);
pr_retainPower_dem=mean(pr_retainPower_dem./(1+pr_retainPower_dem),1)';

writetable(table((-1:0.01:1)',pr_retainPower_aut,pr_retainPower_dem),'../../Figures/Figure_2/thetas.csv')


%% evolution of beliefs

% mean
writetable(table(B(N+(1:N),:)-B(1:N,:)),'../../Figures/Figure_5/beliefs.csv')

% uncertainty
Pinv=P;
for t=1:T
    Pinv(:,:,t)=P(:,:,t)\eye(2*N);
end
uncertainty=zeros(N,T);
for n=1:N
    for t=1:T
        uncertainty(n,t)=sqrt(Pinv(N+n,N+n,t)+Pinv(n,n,t)-2*Pinv(N+n,n,t));
    end
end
writetable(table(uncertainty),'../../Figures/Figure_5/uncertainty_beliefs.csv')

